.class public Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;
.super Landroid/content/BroadcastReceiver;
.source "AudioControlReciever.java"


# static fields
.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final MUTED_VOLUME:I = 0x0

.field private static final NORMAL_VOLUME:I = 0x64

.field private static final TAG:Ljava/lang/String;


# instance fields
.field private mAudioManager:Landroid/media/AudioManager;

.field private final mContext:Landroid/content/Context;

.field private mMediaPlayer:Landroid/media/MediaPlayer;

.field private mRegistered:Z


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 48
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 53
    const-class v0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;

    invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->TAG:Ljava/lang/String;

    return-void
.end method

.method public constructor <init>(Landroid/content/Context;)V
    .locals 1
    .parameter "context"

    .prologue
    .line 80
    invoke-direct {p0}, Landroid/content/BroadcastReceiver;-><init>()V

    .line 81
    iput-object p1, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mContext:Landroid/content/Context;

    .line 82
    const-string v0, "audio"

    invoke-virtual {p1, v0}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/media/AudioManager;

    iput-object v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mAudioManager:Landroid/media/AudioManager;

    .line 83
    return-void
.end method

.method private setVolume(I)V
    .locals 8
    .parameter "amount"

    .prologue
    .line 130
    const/16 v0, 0x64

    .line 131
    .local v0, max:I
    rsub-int/lit8 v4, p1, 0x64

    if-lez v4, :cond_0

    rsub-int/lit8 v4, p1, 0x64

    int-to-double v4, v4

    invoke-static {v4, v5}, Ljava/lang/Math;->log(D)D

    move-result-wide v1

    .line 132
    .local v1, numerator:D
    :goto_0
    const-wide/high16 v4, 0x3ff0

    const-wide/high16 v6, 0x4059

    invoke-static {v6, v7}, Ljava/lang/Math;->log(D)D

    move-result-wide v6

    div-double v6, v1, v6

    sub-double/2addr v4, v6

    double-to-float v3, v4

    .line 134
    .local v3, volume:F
    iget-object v4, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mMediaPlayer:Landroid/media/MediaPlayer;

    if-eqz v4, :cond_1

    .line 135
    iget-object v4, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mMediaPlayer:Landroid/media/MediaPlayer;

    invoke-virtual {v4, v3, v3}, Landroid/media/MediaPlayer;->setVolume(FF)V

    .line 139
    :goto_1
    return-void

    .line 131
    .end local v1           #numerator:D
    .end local v3           #volume:F
    :cond_0
    const-wide/16 v1, 0x0

    goto :goto_0

    .line 137
    .restart local v1       #numerator:D
    .restart local v3       #volume:F
    :cond_1
    sget-object v4, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v5, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->TAG:Ljava/lang/String;

    const-string v6, "Can not set volume for MediaPlayer due it hasn\'t been set before."

    const/4 v7, 0x0

    new-array v7, v7, [Ljava/lang/Object;

    invoke-virtual {v4, v5, v6, v7}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1
.end method


# virtual methods
.method public getMediaPlayer()Landroid/media/MediaPlayer;
    .locals 1

    .prologue
    .line 102
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mMediaPlayer:Landroid/media/MediaPlayer;

    return-object v0
.end method

.method public onReceive(Landroid/content/Context;Landroid/content/Intent;)V
    .locals 5
    .parameter "context"
    .parameter "intent"

    .prologue
    const/4 v4, 0x0

    .line 143
    sget-object v0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v1, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->TAG:Ljava/lang/String;

    const-string v2, "Ringer mode changed"

    new-array v3, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 144
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mAudioManager:Landroid/media/AudioManager;

    invoke-virtual {v0}, Landroid/media/AudioManager;->getRingerMode()I

    move-result v0

    packed-switch v0, :pswitch_data_0

    .line 152
    :goto_0
    return-void

    .line 147
    :pswitch_0
    invoke-direct {p0, v4}, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->setVolume(I)V

    goto :goto_0

    .line 150
    :pswitch_1
    const/16 v0, 0x64

    invoke-direct {p0, v0}, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->setVolume(I)V

    goto :goto_0

    .line 144
    :pswitch_data_0
    .packed-switch 0x0
        :pswitch_0
        :pswitch_0
        :pswitch_1
    .end packed-switch
.end method

.method public registerReciever()V
    .locals 3

    .prologue
    .line 90
    iget-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mRegistered:Z

    if-nez v0, :cond_0

    .line 91
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mContext:Landroid/content/Context;

    new-instance v1, Landroid/content/IntentFilter;

    const-string v2, "android.media.RINGER_MODE_CHANGED"

    invoke-direct {v1, v2}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0, p0, v1}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;

    .line 92
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mRegistered:Z

    .line 94
    :cond_0
    return-void
.end method

.method public setMediaPlayer(Landroid/media/MediaPlayer;)V
    .locals 0
    .parameter "player"

    .prologue
    .line 111
    iput-object p1, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mMediaPlayer:Landroid/media/MediaPlayer;

    .line 112
    return-void
.end method

.method public unRegisterReciever()V
    .locals 1

    .prologue
    .line 118
    iget-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mRegistered:Z

    if-eqz v0, :cond_0

    .line 119
    iget-object v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mContext:Landroid/content/Context;

    invoke-virtual {v0, p0}, Landroid/content/Context;->unregisterReceiver(Landroid/content/BroadcastReceiver;)V

    .line 120
    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/burstly/lib/component/networkcomponent/burstly/AudioControlReciever;->mRegistered:Z

    .line 122
    :cond_0
    return-void
.end method
